package com.wei.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wei.entity.Course;
import com.wei.entity.Teacher;
import com.wei.service.CourseService;
import com.wei.service.TeacherService;
import com.wei.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author wjx
 * @ClassName TeacherFrontController
 * @description: TODO
 * @date 2022-12-02 13:12
 * @version: 1.0
 */
@RestController
@RequestMapping("/eduservice/teacher")

public class TeacherFrontController {

    @Autowired
    private TeacherService teacherService;

    @Autowired
    private CourseService courseService;

    /**
     * 显示讲师信息
     *
     * @param current
     * @param limit
     * @return
     */
    @GetMapping("/getTeacherInfo/{current}/{limit}")
    public R getTeacherInfo(@PathVariable Long current, @PathVariable Long limit) {

        Map<String, Object> map = teacherService.showTeacherInfo(current, limit);

        return R.ok().data("map", map);
    }

    @GetMapping("/getTeacherInfoById/{teacherId}")
    public R getTeacherInfoById(@PathVariable String teacherId) {

        //获取讲师信息
        Teacher teacher = teacherService.getById(teacherId);

        //获取讲师所讲课程
        LambdaQueryWrapper<Course> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Course::getTeacherId, teacherId);

        List<Course> courseList = courseService.list(queryWrapper);

        return R.ok().data("teacher", teacher).data("courseList", courseList);
    }
}
